import { defineStore } from 'pinia';
import { computed, ref } from 'vue';
import { useInfoStore } from './s2.js';
import { info } from 'sass';
// shop模块
export const useShopStore = defineStore('shop123', {
  state: () => ({
    title: 'hello shop',
    num: 100,
  }),
  getters: {
    g1: (state) => state.title + '!!',
    g2: function (state) {
      return 'title:' + this.g1
    },
    g3: (state) => {
      return (x) => {
        return state.num + x
      }
    }
  },
  actions: {
    add(x, y) {
      return x + y;
    },
    say() {
      console.log(this.add(100, 200));
    }
  },
});

// cart模块
export const useCartStore = defineStore('cart', () => {
  // 获取useShopStore对象
  const shopStore = useShopStore();
  // 获取useInfoStore对象
  const infoStroe = useInfoStore();

  const title = ref('hello cart');
  const num = ref(100);
  const g1 = computed(() => {
    return title.value + '!!'
  });

  const g2 = computed(() => {
    return 'title:' + g1.value;
  });

  const g3 = computed(() => {
    return (x) => x + num.value;
  });

  const g4 = computed(() => {
    return 'cart store:' + shopStore.title + ' ' + infoStroe.title;
  });


  const add = function (x, y) {
    return x + y;
  }

  const say = function () {
    console.log(add(100, 200), shopStore.add(1000, 2000), infoStroe.add(14, 19));
  }

  return {
    title,
    g1,
    g2,
    g3,
    g4,
    add,
    say,
    num
  }
});
